package com.shensi.adminCollect.controller.fleet;

import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.common.core.page.TableDataInfo;
import com.shensi.adminCollect.domain.fleet.form.FleetCardSubAddForm;
import com.shensi.adminCollect.domain.fleet.form.FleetCardSubForm;
import com.shensi.adminCollect.domain.fleet.form.FleetCardSubQueryForm;
import com.shensi.adminCollect.domain.fleet.vo.FleetCardSubVo;
import com.shensi.adminCollect.service.fleet.FleetCardSubService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Api(tags = "车队卡子卡管理")
@RestController
@RequestMapping("/fleetCard/sub")
public class FleetCardSubController extends BaseController {

    @Autowired
    private FleetCardSubService fleetCardSubService;

    @ApiOperation(value = "车队卡子卡分页列表", notes = "车队卡子卡分页列表")
    @GetMapping("/page")
    public TableDataInfo page(FleetCardSubQueryForm fleetCardSubQueryForm) {
        startPage();
        List<FleetCardSubVo> list = fleetCardSubService.selectFleetCardSubList(fleetCardSubQueryForm);
        return getDataTable(list);
    }

    @ApiOperation(value = "修改车队子卡", notes = "修改车队子卡")
    @PutMapping("/{id}")
    public AjaxResult edit(@PathVariable Long id, @RequestBody FleetCardSubForm fleetCardSubForm) {
        return toAjax(fleetCardSubService.updateFleetCardSub(id, fleetCardSubForm));
    }

    @ApiOperation(value = "子卡分配金额", notes = "子卡分配金额")
    @PutMapping("/allocationAmount/{allocationAmount}/id/{id}")
    public AjaxResult allocationAmount(@PathVariable BigDecimal allocationAmount, @PathVariable Long id) {
        return toAjax(fleetCardSubService.updateAllocationAmount(allocationAmount, id));
    }

    @ApiOperation(value = "回收子卡额度", notes = "回收子卡额度")
    @PutMapping("/recovery/{id}")
    public AjaxResult recovery(@PathVariable Long id) {
        return toAjax(fleetCardSubService.recovery(id));
    }

    @ApiOperation(value = "车队子卡审核", notes = "车队子卡审核")
    @PutMapping("/review/{id}/status/{status}")
    public AjaxResult review(@PathVariable Long id, @PathVariable Integer status) {
        return toAjax(fleetCardSubService.review(id, status));
    }

    @ApiOperation(value = "删除车队子卡", notes = "删除车队子卡")
    @DeleteMapping("/{ids}")
    public AjaxResult deleted(@PathVariable List<Long> ids) {
        return toAjax(fleetCardSubService.deleted(ids));
    }

    @ApiOperation(value = "新增车队子卡", notes = "新增车队子卡")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FleetCardSubAddForm fleetCardSubAddForm) {
        return toAjax(fleetCardSubService.addFleetCardSub(fleetCardSubAddForm));
    }
}
